package com.ruoyi.web.controller.common;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ResultResponse;
import com.ruoyi.file.domain.FileConf;
import com.ruoyi.file.service.IFileConfService;
import com.ruoyi.file.service.IFileInfoService;
import com.ruoyi.file.service.IFtpFileService;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Controller
@RequestMapping("/ftp")
public class FtpFileController {

    @Autowired
    private IFileInfoService iFileInfoService;

    @Value("${ftp.picserver}")
    private String picserver;

    @PostMapping("/upload")
    @ResponseBody
    public AjaxResult uploadFile(HttpServletRequest request, MultipartFile file, String bizeType) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        // 获得文件：
        MultipartFile file1 = multipartRequest.getFile("file");
        ResultResponse resultResponse = iFileInfoService.uploadFile(file1, bizeType);
        if(resultResponse.isSuccess()){
            AjaxResult ajax = AjaxResult.success();
            ajax.put("fileInfoId", resultResponse.get("fileInfoId"));
            ajax.put("textStatus","parsererror");
            return ajax;
        }
        //return null;
        AjaxResult error = AjaxResult.error(resultResponse.getMsg());
        error.put("textStatus","parsererror");

        return error;

    }


}
